﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;

namespace PagesList
{
    public partial class ThirdPage : UserControl
    {
        public ThirdPage()
        {
            InitializeComponent();
            ShowData();
        }

        public void ShowData()
        {
            OleDbCommandBuilder oledbCmdBuilder;
            ds = new DataSet();
            
            string sql = null;
            connection = ConnectManager.GetSystemConnect();
            if (textBox1.Text == "")
            {
                sql = "select (select ltrim(mc)  from xt_qh where xt_qh.dh=LEFT(a.dh,1)),(select ltrim(mc)  from xt_qh where xt_qh.dh=LEFT(a.dh,2)),(select ltrim(mc) from xt_qh where xt_qh.dh=LEFT(a.dh,3)) ,dh ,mc,[password],PassWord1,PassWord2 from xt_yymc_print a  ";
            }
            else
            {
                sql = "select (select ltrim(mc)  from xt_qh where xt_qh.dh=LEFT(a.dh,1)),(select ltrim(mc)  from xt_qh where xt_qh.dh=LEFT(a.dh,2)),(select ltrim(mc) from xt_qh where xt_qh.dh=LEFT(a.dh,3)) ,dh ,mc,[password],PassWord1,PassWord2 from xt_yymc_print a where mc like '%" + textBox1.Text + "%'";
            }
            try
            {
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
                oledbAdapter.Fill(ds);
                this.dataGridView1.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

             dataGridView1.Columns[0].HeaderText = "省";
             dataGridView1.Columns[1].HeaderText = "市";
             dataGridView1.Columns[2].HeaderText = "县";
             dataGridView1.Columns[3].HeaderText = "编码";
             dataGridView1.Columns[4].HeaderText = "医院";
             dataGridView1.Columns[5].HeaderText = "总密码";
             dataGridView1.Columns[6].HeaderText = "现金密码";
             dataGridView1.Columns[7].HeaderText = "非现金密码";

        }

        protected void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
        {
            if (ds == null || oledbAdapter == null)
            {
                return;
            }
            oledbAdapter.Update(ds);
        }

        private OleDbConnection connection;
        private OleDbDataAdapter oledbAdapter;
        private DataSet ds;

        private void ThirdPage_Resize(object sender, EventArgs e)
        {
            this.dataGridView1.Size = this.Size - new System.Drawing.Size(100, 100);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ExcelExportTool.DataGridViewToExcel(this.dataGridView1);
        }


    }
}
